package com.example.cloudstreamrocketmqprovider8801.provider;

import com.example.cloudstreamrocketmqprovider8801.channal.CustomerBinder;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * @ClassName: MessageProviderImpl
 * @Description:
 * @Date 2024/03/05 15:29
 * @Author songshaoqiu
 **/
@Component
@Slf4j
public class MessageProviderImpl implements IMessageProvider{

    @Autowired
    public CustomerBinder customerBinder;

    @Override
    public String send(String msg) {
        Message<String> message = MessageBuilder.withPayload(msg)
                .setHeader(RocketMQHeaders.TAGS, "TAG1")
                .build();
        boolean send = customerBinder.sendToOneChannel().send(message);
        log.info("oneChannel 发送消息结果{}",send);
        if (send){
            return "success";
        }else {
            return "fail";
        }
    }
}
